<div id="div2_chart"></div>
<script>
    var kategori = [];
    var series = [];
    var kat = [];
    var ser = [];
<?php

function format_angka($angka) {
    $len = strlen($angka);
    $res = "";
    $c = 0;
    while ($len > 0) {
        $len--;
        $res = $angka[$len] . $res;
        $c = ($c + 1) % 3;
        if ($c == 0 && $len > 0)
            $res = "." . $res;
    }
    return $res;
}

//var_dump($data);
$counter = 0;
$jumlah_balita = 0;
$jumlah_total = 0;
foreach ($data as $pekerjaan) {
    $jumlah_balita+=$pekerjaan->jumlah_balita;
    $jumlah_total+=$pekerjaan->jumlah_total;
}
?>
    ser.push(['<?= $kolom2 ?>',<?= $jumlah_balita ?>]);
    ser.push(['<?= $kolom3 ?>',<?= $jumlah_total-$jumlah_balita ?>]);

    $('#div2_chart').highcharts({
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: 0, //null,
            plotShadow: false
        },
        title: {
            text: '<?= $judul ?>'
        },
        subtitle: {
            text: '<?php
if (isset($subtitle))
    echo implode('-', $subtitle);
else
    echo 'Banyuwangi';
?>'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.y}</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                    }
                }
            }
        },
        series: [{
                type: 'pie',
                name: 'Jumlah',
                data: ser
            }]
    });

</script>
<div style="margin-top: 40px">
    <table class="table table-striped">
        <tr>
            <th>No</th>
            <th><?= $kolom ?></th>
            <th style="text-align: right">Prosentase</th>
            <th style="text-align: right" colspan=""><?= $kolom2 ?></th>
            <th style="text-align: right">Jumlah Total</th>
            <?php
            $session = $this->session->userdata('login');
            $logged_in = false;
            if ($session != null) {
                $logged_in = true;
            }
            if ($logged_in) {
                ?>
                <th style="text-align: right">Aksi</th>
                <?php
            }
            ?>
        </tr>
        <?php
        $tot = 0;
        $no = 0;
        foreach ($data as $row) {
            $no++;
            ?>
            <tr>
                <td><?= $no ?></td>
                <td><?= $row->kategori ?></td>
                <td style="width:10px;text-align: right"><?= number_format(100 * ($row->jumlah_balita / $row->jumlah_total), 2) ?>%</td>
                <td style="text-align: right"><?= format_angka($row->jumlah_balita); ?></td>

                <td style="text-align: right"><?= format_angka($row->jumlah_total); ?></td>
                <?php
                if ($logged_in) {
                    ?>
                    <td style="text-align: right"><a href="<?= site_url() . '/' . $controller ?>?<?php
                                                     if (isset($id_kecamatan) && $id_kecamatan > 0) {
                                                         echo 'id_kecamatan=' . $id_kecamatan . '&';
                                                         if (isset($id_kelurahan) && $id_kelurahan > 0) {
                                                             echo 'id_kelurahan=' . $id_kelurahan . '&';
                                                         }else{
                                                             echo 'id_kelurahan=' . $row->kategori_id;
                                                         }
                                                     } else{
                                                         echo 'id_kecamatan=' . $row->kategori_id;
                                                     }
                                                     ?>">Lihat</a></td>
                                                     <?php
                    }
                    ?>
            </tr>
            <?php
        }
        ?>
    </table>
</div>